<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>看跌合买记录</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/own.css"/>
    <script type="text/javascript" src="../../js/mui.min.js" ></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/echarts.common.min.js"></script>
	<script>
		
	mui.init({});
	mui.plusReady(function(){  
			//初始化监听头部和底部事件
			tzdr.init.initHearListener();
			var win = plus.webview.currentWebview();
			var tradeID = win.tradeID;
			var direction = win.direction;
			var fullCopies = win.fullCopies;
			var price = win.price;
			if (mui.isnull(tradeID) || mui.isnull(direction) || mui.isnull(fullCopies) || mui.isnull(price)){
				return;
			}
			//alert(direction);
			//获取数据
		    mui.app_request('/ftogether_trade/trade_record_detail',{"tradeID":tradeID,"direction":direction},
			function(result){ 
				var copies = result.data.statistics.copies;
				var backCopies = parseInt(copies%fullCopies);
				var fullOrders = parseInt(copies/fullCopies);
				
				var tradeStatus = result.data.trade.status;
				if (tradeStatus==1){
					document.getElementById("topayBtn").style.display="block";
				}
				// 设置统计值
				if (direction==1){
					document.getElementById("statisticsRise").style.display="block"; 
					document.getElementById("statisticsDrop").style.display="none";
					document.getElementById("statisticsRise").lastChild.innerHTML='看涨方向：合买<i>'+copies+'份</i>'+((tradeStatus>1)?'操盘<i>'+fullOrders+'单</i>退<i>'+backCopies+'份</i>':'满<i>'+fullOrders+'单</i>');
					document.getElementById("topayBtn").innerHTML="我也要看涨";
					document.getElementById("record_title").innerHTML="看涨合买记录";
					document.getElementById("topayBtn").style.backgroundColor="#ff6663";
				}
				else
				{
					document.getElementById("statisticsRise").style.display="none";
					document.getElementById("statisticsDrop").style.display="block";
					document.getElementById("statisticsDrop").lastChild.innerHTML='看跌方向：合买<i>'+copies+'份</i>'+((tradeStatus>1)?'操盘<i>'+fullOrders+'单</i>退<i>'+backCopies+'份</i>':'满<i>'+fullOrders+'单</i>');
					document.getElementById("topayBtn").innerHTML="我也要看跌";	
					document.getElementById("record_title").innerHTML="看跌合买记录";
				}
				// 遍历数组显示所有记录
				var _html ="<thead><td>合买时间</td><td>合买者</td><td>过去盈利率</td><td>第几单</td></thead>";
				var orderCount = 1;
				for(var i in result.data.records){
					
					if (result.data.records[i].is_back==1){
						_html+='<tr class="no">';
					}else
					{
						_html+='<tr>';
					}
					_html+='<td>'+result.data.records[i].buyTime+'</td>';
					_html+='<td>'+hideMobile(result.data.records[i].mobile)+'</td>'; 
					_html+='<td>'+(mui.isnull(result.data.records[i].percent)?0.00:result.data.records[i].percent)+'%</td>';
					if (i%fullCopies==0 && result.data.records[i].is_back==0){
						_html+='<td rowspan="'+fullCopies+'">第'+orderCount+'单</td>';
						orderCount ++;
					}
					if (result.data.records[i].is_back==1){
						_html+='<td></td>';
					}
					
					_html+='</tr>';
				}
				document.getElementById("recordTab").innerHTML=_html;
  			},
  			function(result){ 
  			
      		});
      		
      		//参与提交
			document.getElementById("topayBtn").addEventListener("tap",function(){ 
				if(mui.cacheUser.isLogin()){
					var p=plus.webview.getWebviewById("togetherPay");
					if(p){
							mui.app_refresh('togetherPay');   
					}
					mui.openWindow({url:"/tzdr/buy/pay.html",id:"togetherPay",extras:{tradeID:tradeID,direction:direction,price:price,pageID:"tradeRecord"}});
				}else
				{
					mui.openWindow({url:"../login/login.html",id:"login",extras:{backpageID:"buyDate"}});
				}
		   }); 
	});
	
	 /**
		     * 隐藏手机号码
		     * @param {Object} mobile
		     */
		    function hideMobile(mobile){
		    	
		    	if (mui.isnull(mobile)){
		    		return mobile;
		    	}
		    	
		    	var result = mobile;
		    	if (mobile.length>=11){
		    		result =  mobile.substr(0,3)+"****"+mobile.substr(7);
		    	}
		    	
		    	var cacheMobile = mui.cacheUser.get(tzdr.constants.user_mobile);
		    	//alert(tzdr.cacheUser.get(tzdr.constants.user_mobile););
		    	if (cacheMobile==mobile){
		    		result = result+"<br>(自己)";
		    	}
		    	return result;
		    }
	</script>
</head>
<body>
<header class="mui-bar mui-bar-nav own-topbg">
	<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a> 
	<h1 class="mui-title" id="record_title">合买记录</h1>		
</header>
<div class="mui-content buy_record">
	<h2 id="statisticsDrop" style="display: none;"><img src="../../images/br_01.png"><span>看跌方向：合买<i>0份</i>操盘<i>0单</i>退<i>0份</i></span></h2>
	<h2 id="statisticsRise" style="display: none;"><img src="../../images/br_02.png"><span>看涨方向：合买<i>0份</i>操盘<i>0单</i>退<i>0份</i></span></h2>
	<table cellpadding="0" cellspacing="0" border="0" id="recordTab">
		<thead>
			<td>合买时间</td>
			<td>合买者</td>
			<td>过去盈利率</td>
			<td>第几单</td>
		</thead>
		<!--<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
			<td rowspan="4">第1单</td>
		</tr>
		<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
		</tr>
		<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
		</tr>
		<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
		</tr>		
		<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
			<td rowspan="4">第2单</td>
		</tr>
		<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
		</tr>
		<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
		</tr>
		<tr>
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
		</tr>
		<tr class="no">
			<td>04.08 10:22</td>
			<td>186****3399</td>
			<td>45.34%</td>
			<td></td>
		</tr>-->
	</table>
	<p>合买停止时，未满单的合买失效，系统会自动退款</p>
	<div class="ac_btn buy_btn">
		<button class="mui-btn mui-btn-block pay_btn" type="button" style="display: none;" id="topayBtn">我也要看跌</button>
	</div>		
</div>
</body>
</html>